var appApi = require('./app-api');
var co = require('co');
function asyncRouter(router) {
  var ret = {};
  function addMethod(method) {
    ret[method] = function(path, handlerGenerator) {
        router[method](path, function(req, res, next) {
          co.wrap(handlerGenerator)(req,res, next).catch(appApi.forwardError(res));
        });
      };
  }
  addMethod('get');
  addMethod('put');
  addMethod('post');
  return ret;
}
module.exports = asyncRouter;